<?php

namespace app\shadmin\controller;


use think\Db;
use think\Request;


class Dev extends \think\Controller
{
    public function _initialize()
    {
        // parent::_initialize();
        if (!session('?aid')) {

            $this->redirect('shadmin/login/index');


        }

    }


//删除aPI

    public function delapi(){

       if(IS_AJAX()){
           $s=input('param.');
           if($s['t'] && $s['k'] && $s['v']){

               $flag=Db::table($s['t'])->where([$s['k']=>$s['v']])->delete();
               $json['code']=$flag ? 200 : 400;

               sys_log(session('aid'),$s['v'],session('name').$s['title']);

           }else{

               $json['code']=400;
               $json['msg']="参数不全";
               $json['s']=$s;




           }




       }


       return json($json);




    }

   //上架下架api
    //
    public function changeapi()
    {

        if (IS_AJAX()) {
            $s = input('param.');
            $data['state'] = $s['val'];
            $where['id'] = $s['key'];
            $flag = Db::table($s['table'])->where($where)->update($data);
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."修改了产品状态");
            return json($json);


        }


    }


//修改积分商城
    public function changejifen()
    {

        if (IS_AJAX()) {
            $s = input('param.');
            $data['state'] = $s['state'];
            $where['id'] = $s['id'];
            $flag = Db::table('jifen_product')->where($where)->update($data);
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."修改了秒杀商品状态");
            return json($json);


        }


    }

//修改秒杀产品状态
    public function seckillstate()
    {

        if (IS_AJAX()) {
            $s = input('param.');
            $data['state'] = $s['state'];
            $where['id'] = $s['id'];
            $flag = Db::table('so9_seckill')->where($where)->update($data);
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."修改了秒杀商品状态");
            return json($json);


        }


    }



//修改集单产品状态
    public function gatherstate()
    {

        if (IS_AJAX()) {
            $s = input('param.');
            $data['state'] = $s['state'];
            $where['id'] = $s['id'];
            $flag = Db::table('so9_gather')->where($where)->update($data);
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."修改了集单商品状态");
            return json($json);


        }


    }


//修改小时购
     public function hourstate()
    {

        if (IS_AJAX()) {
            $s = input('param.');
            $data['state'] = $s['state'];
            $where['id'] = $s['id'];
            $flag = Db::table('so9_hour')->where($where)->update($data);
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."修改了小时购状态");
            return json($json);


        }


    }

//拼团
     public function togetherstate()
    {

        if (IS_AJAX()) {
            $s = input('param.');
            $data['state'] = $s['state'];
            $where['id'] = $s['id'];
            $flag = Db::table('so9_together')->where($where)->update($data);
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."修改了拼团商品状态");
            return json($json);


        }


    }


//修改新闻状态
    public function changnews()
    {

        if (IS_AJAX()) {
            $s = input('param.');
            $data['State'] = $s['key'];
            $where['ID'] = $s['id'];
            $flag = Db::table('news')->where($where)->update($data);
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."修改了新闻状态");
            return json($json);


        }


    }


        public function changepro()
    {

        if (IS_AJAX()) {
            $s = input('param.');
            $data['state'] = $s['key'];
            $where['id'] = $s['id'];
            $flag = Db::table('product_1')->where($where)->update($data);
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."修改了产品状态");
            return json($json);


        }


    }

    //删除产品
    public function delpro()
    {

        if (IS_AJAX()) {
            $s = input('param.');

            $where['ID'] = $s['id'];
            $flag = Db::table('product')->where($where)->delete();
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."删除了商品");
            return json($json);


        }


    }


    //删除新闻
    public function delnews()
    {

        if (IS_AJAX()) {
            $s = input('param.');

            $where['ID'] = $s['id'];
            $flag = Db::table('news')->where($where)->delete();
            $json['code'] = $flag ? 200 : 400;
            sys_log(session('aid'),$s['id'],session('name')."删除了新闻");
            return json($json);


        }


    }


}

